﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using lgweb.common;
using LGCourt.Logic.BLL;
using KMFrame.Core;
using LGCourt.Logic.NBL.DBEntities;
using LGCourt.Logic.Common;

namespace lgweb.inside.FocusNews
{
    public partial class list : NeedValidatePage
    {
        private int _pageIndex = 1;
        public string _cate = "1";
        private string _cateName = "法院新闻";
        private string _dept = string.Empty;
        private string _keyword = string.Empty;
        private string _start = string.Empty;
        private string _end = string.Empty;
        public int _ClassID = 0;
        protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!this.IsPostBack)
            {
                GetParam();
                GetDepartmentList();
                GetList();
            }
        }

        private void GetParam()
        {
            this._cate = string.IsNullOrEmpty(Request.QueryString["cate"]) ? "0" : Request.QueryString["cate"];
            this._dept = string.IsNullOrEmpty(Request.QueryString["dept"]) ? "" : Request.QueryString["dept"];
            this._keyword = string.IsNullOrEmpty(Request.QueryString["keyword"]) ? "" : Request.QueryString["keyword"];
            this._start = string.IsNullOrEmpty(Request.QueryString["start"]) ? "" : Request.QueryString["start"];
            this._end = string.IsNullOrEmpty(Request.QueryString["end"]) ? "" : Request.QueryString["end"];
            //switch (_cate)
            //{
            //    case "0":
            //        this._cateName = "图片新闻";
            //        break;
            //    case "1":
            //        this._cateName = "时事要闻";
            //        break;
            //    case "2":
            //        this._cateName = "法治聚焦";
            //        break;
            //    default:
            //        break;

            //}
            //this.spBaoCate.InnerHtml = this._cateName;
            this._pageIndex = string.IsNullOrEmpty(Request.QueryString["PageIndex"]) ? 1 : Convert.ToInt32(Request.QueryString["PageIndex"]);
        }

        //绑定部门
        private void GetDepartmentList()
        {
            DepartmentHandler bll = new DepartmentHandler();
            List<Department> result = (List<Department>)bll.GetDepartmentList();
            if (result != null && result.Count>0)
            {
                Department PleaseLocation = new Department();
                PleaseLocation.Code = "0";
                PleaseLocation.Name = "选择部门";
                result.Insert(0, PleaseLocation);
                this.sltDepartment.DataSource = result;
                this.sltDepartment.DataTextField = "Name";
                this.sltDepartment.DataValueField = "Name";
                this.sltDepartment.DataBind();
                this.sltDepartment.Value = this._dept;
            }
            this.txtKeyword.Value = _keyword;
            this.txtStartDate.Value = _start;
            this.txtEndDate.Value = _end;
        }

        private void GetList()
        {
            ColInfo bll = new ColInfo();
            DeptClassCondition classParam = new DeptClassCondition();
            classParam.Name = "首页栏目";
            if (int.Parse(_cate) > 0)
            {
                List<V_DICT_SOURCE> classInfoList = bll.GetDeptSourceList(classParam);
                if (classInfoList.Count >= int.Parse(_cate))
                {
                    V_DICT_SOURCE classInfo = classInfoList[int.Parse(_cate) - 1];
                    _ClassID = classInfo.ID.GetValueOrDefault(0);
                    this.spBaoCate.InnerHtml = classInfo.Source;
                }
            }
            else
            {
                this.spBaoCate.InnerHtml = "图片新闻";
            }
            //BBS bll = new BBS();
            //InfoCondition param = new InfoCondition();
            //param.PageSize = 20;
            //param.PageIndex = this._pageIndex;
            //param.InfoTag = this._cateName;           
            QueryCondition param = new QueryCondition();
            param.PageSize = 20;
            param.PageIndex = this._pageIndex;
            if (!string.IsNullOrEmpty(this._start))
            {
                param.BegingDate = DateTime.Parse(this._start);
            }
            if (!string.IsNullOrEmpty(this._end))
            {
                param.EndDate =DateTime.Parse(this._end);
            }
            param.ClassID = _ClassID;
            param.keyword = this._keyword;
            param.from = this._dept;

            //PageResult result = (PageResult)bll.GetNewsInfoPage(param);
            PageResult result =null;
            if(_cate!="0")
               result=  (PageResult)bll.GetNewsInfoPage(param);
            else
               result = (PageResult)bll.GetPicInfoPage(param);
            if (result != null && result.ResultList != null)
            {
                //this.rptInfoList.DataSource = (List<vPortalArticleTitleEx>)result.ResultList;
                if(_cate!="0")
                    this.rptInfoList.DataSource = (List<LGFY_Platform_Articles>)result.ResultList;
                else
                    this.rptInfoList.DataSource = (List<LGFY_Platform_NewsOfPic>)result.ResultList;
                this.rptInfoList.DataBind();
                this.pager1.RecordCount = result.TotalCount;
                this.pager1.TotalPage = result.PageCount;
                this.pager1.PageIndex = this._pageIndex;
                this.pager1.PageSize = 20;
                this.pager1.LinkUrl = string.Format("/inside/FocusNews/list.aspx?PageIndex={0}&cate={1}&keyword={2}&dept={3}&start={4}&end={5}", this._pageIndex, _cate, this._keyword, this._dept, this._start, this._end);
            }
        }
    }
}